/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cs5631threadinglab;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author brady
 */
public class Cell {
    int row;
    int col;
    LinkedList<Particle> particles;

    /**
     * constructor, also creates a particle in it too
     * @param row row in the environment
     * @param col column in the environment
     * @param particleId ID of the particle to be made in this cell
     */
    public Cell(int row, int col, int particleId)
    {
        particles = new LinkedList<Particle>();
        this.row = row;
        this.col = col;
        particles.add(new Particle(particleId));
    }

    /**
     * releases a particle from the cell if any are available
     * @return the particle released
     */
    synchronized Particle ReleaseParticle()
    {
        Particle p = null;
        if(!particles.isEmpty())
            p = particles.remove();
        else p = null;
        return p;
    }

    /**
     * accepts a particle into the cell
     * @param p particle to accept
     * @return true on success, false otherwise
     */
    synchronized boolean AcceptParticle(Particle p)
    {
        return particles.add(p);
    }
    
}
